package com.atguigu.springbootdemo.service;

import com.atguigu.springbootdemo.bean.Employee;
import com.atguigu.springbootdemo.bean.Region;
import com.atguigu.springbootdemo.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Smexy on 2022/12/5
 *
 *  每种业务，必须，先做1，再操作业务，再做2
 *
 *      @Service的作用:
 *              1.给你自己看，代表这个是一个业务模型类
 *              2.容器扫描到后，会自动为这个注解标注的类，创建一个单例对象
 */
@Service
public class EmployeeServiceImpl2 implements EmployeeService
{
    @Autowired
    private EmployeeMapper dao;

    @Override
    public Employee getEmployeeById(Integer id) {

        System.out.println("先做1");

        Employee e = dao.getEmployeeById(id+1);

        System.out.println("再做2");

        return e;
    }

    @Override
    public void insertEmployee(Employee e) {

        System.out.println("先做1");

        dao.insertEmployee(e);

        System.out.println("再做2");

    }

    @Override
    public void updateEmployee(Employee e) {

        System.out.println("先做1");

        dao.updateEmployee(e);

        System.out.println("再做2");

    }

    @Override
    public void deleteEmployeeById(Integer id) {

        System.out.println("先做1");

        dao.deleteEmployeeById(id);

        System.out.println("再做2");

    }

    @Override
    public List<Employee> getAll() {

        System.out.println("先做1");

        List<Employee> all = dao.getAll();

        System.out.println("再做2");

        return all;
    }

    @Override
    public List<Region> getAllRegion() {
        return dao.getAllRegion();
    }
}
